package com.qj.yantaishan.controller;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qj.yantaishan.common.annotation.Log;
import com.qj.yantaishan.common.enums.BusinessType;
import com.qj.yantaishan.domain.MySupplier;
import com.qj.yantaishan.service.IMySupplierService;
import com.qj.yantaishan.common.core.controller.BaseController;
import com.qj.yantaishan.common.core.domain.AjaxResult;
import com.qj.yantaishan.common.utils.poi.ExcelUtil;
import com.qj.yantaishan.common.core.page.TableDataInfo;

/**
 * 我的供货商Controller
 * 
 * @author qihe
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/yantaishan/MySupplier")
public class MySupplierController extends BaseController
{
    private String prefix = "yantaishan/MySupplier";

    @Autowired
    private IMySupplierService mySupplierService;

    @RequiresPermissions("yantaishan:supplier:view")
    @GetMapping()
    public String supplier()
    {
        return prefix + "/supplier";
    }

    /**
     * 查询我的供货商列表
     */
    @RequiresPermissions("yantaishan:supplier:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MySupplier mySupplier)
    {
        startPage();
        List<MySupplier> list = mySupplierService.selectMySupplierList(mySupplier);
        return getDataTable(list);
    }

    /**
     * 导出我的供货商列表
     */
    @RequiresPermissions("yantaishan:supplier:export")
    @Log(title = "我的供货商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MySupplier mySupplier)
    {
        List<MySupplier> list = mySupplierService.selectMySupplierList(mySupplier);
        ExcelUtil<MySupplier> util = new ExcelUtil<MySupplier>(MySupplier.class);
        return util.exportExcel(list, "我的供货商数据");
    }

    /**
     * 新增我的供货商
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存我的供货商
     */
    @RequiresPermissions("yantaishan:supplier:add")
    @Log(title = "我的供货商", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MySupplier mySupplier)
    {
        return toAjax(mySupplierService.insertMySupplier(mySupplier));
    }

    /**
     * 修改我的供货商
     */
    @RequiresPermissions("yantaishan:supplier:edit")
    @GetMapping("/edit/{sellerStoreId}")
    public String edit(@PathVariable("sellerStoreId") Long sellerStoreId, ModelMap mmap)
    {
        MySupplier mySupplier = mySupplierService.selectMySupplierBySellerStoreId(sellerStoreId);
        mmap.put("mySupplier", mySupplier);
        return prefix + "/edit";
    }

    /**
     * 修改保存我的供货商
     */
    @RequiresPermissions("yantaishan:supplier:edit")
    @Log(title = "我的供货商", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MySupplier mySupplier)
    {
        return toAjax(mySupplierService.updateMySupplier(mySupplier));
    }

    /**
     * 删除我的供货商
     */
    @RequiresPermissions("yantaishan:supplier:remove")
    @Log(title = "我的供货商", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mySupplierService.deleteMySupplierBySellerStoreIds(ids));
    }
}
